package com.tiny.pong;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.event.KeyEvent;

import com.tiny.core.game.states.GameState;
import com.tiny.core.game.states.StateBasedGame;
import com.tiny.core.input.KeyboardManager;
import com.tiny.gui.utils.CenteredText;

public class Menu implements GameState {

    private Font f;
    private Font fsmall;
    private CenteredText title;
    private CenteredText instruction;
    private CenteredText start;

    @Override
    public void onLoad(StateBasedGame game) {
        f = new Font("arial", Font.BOLD, 56);
        fsmall = new Font("arial", Font.BOLD, 18);
        title = new CenteredText(game.getWidth(), 200, 0, 0, "Tiny Pong!", f, Color.WHITE);
        title.prepare();

        instruction = new CenteredText(game.getWidth(), 200, 0, 200, "'Q' and 'A' moves player 2 | 'Up' and 'Down' moves player 1", fsmall, Color.WHITE);
        instruction.prepare();

        start = new CenteredText(game.getWidth(), 200, 0, 400, "Presse 'Enter' to start!", fsmall, Color.WHITE);
        start.prepare();
    }

    @Override
    public void onRender(Graphics2D g, StateBasedGame game) {
        title.render(g);
        instruction.render(g);
        start.render(g);
    }

    @Override
    public void onUnload(StateBasedGame game) {
        
    }

    @Override
    public void onUpdate(int currentTick, StateBasedGame game) {
        if (KeyboardManager.getInstance().isPressed(KeyEvent.VK_ENTER)) {
            game.enterState(Main.GAME);
        }

        if (KeyboardManager.getInstance().isPressed(KeyEvent.VK_ESCAPE)) {
            game.terminate();
        }
    }
}
